package com.bysj.sausys.activiti.service;

import com.bysj.sausys.activiti.common.ActivitiUtil;
import com.bysj.sausys.common.AssConst;
import com.bysj.sausys.model.SysAssCancel;
import com.bysj.sausys.service.ISysAssCancelService;
import com.bysj.sausys.service.ISysAssService;
import com.bysj.sausys.service.ISysUserService;
import com.bysj.sausys.util.SpringContextUtil;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 社团注销service任务自动执行
 *
 * @author WangZK
 */
public class AssCancelAuditPassServiceTask implements JavaDelegate {

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        String processInstanceId = delegateExecution.getProcessInstanceId();
        ProcessInstance processInstance = ActivitiUtil.getProcessInstance(processInstanceId);

        String key = processInstance.getBusinessKey();
        if (StringUtils.isNotBlank(key)) {
            int id = Integer.parseInt(key.split("\\.")[1]);
            ISysAssCancelService sysAssCancelService = SpringContextUtil.getBean("sysAssCancelService");
            SysAssCancel sysAssCancel = sysAssCancelService.findById(id);

            Map map = new HashMap(4);
            map.put("id", id);
            map.put("auditStatus", AssConst.ASS_CANCEL_AUDIT_PASS.getCode());

            sysAssCancelService.auditPass(map, sysAssCancel);
        }

    }
}
